Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Modbus Sunspec compatibility to opendtu-onbattery #1150

Open
wants to merge 67 commits into
base: development
Choose a base branch
from

Conversation

AloisKlingler
Copy link

@AloisKlingler AloisKlingler commented Aug 3, 2024

this implementation is (maybe only partially) modbus-sunspec compatibility to simulate a sunspec energy-meter.

to have calculation (especially self-consumption) correct for e.g. fronius solar web you need to either place a 300€ fronius smart meter before each "foreign" inverter.

With this PR it is possible to configure OpenDTU with it's IP-address as a "Smartmeter" on Fronius Gen24 or Fronius Symo inverter. so the Fronius Inverter is able to poll current production and overall production continuously like a from a real fronius-smartmeter.

necessary configuration on OpenDTU:
image

configuration on an Gen24 Inverter:
image

visualisation on an Gen24 inverter:
image

visualisation of the additional "Smartmeter" in Fronius Solarweb as "Additional AC Source":
image

visualisation of the "Smartmeter" data in Solarweb is available as common curve like other inverters are:
image

for my OpenDTU (and also some other users of photovoltaikforum.com) this implementation is running now over a year (more or less) flawless.

to the PR: the tree conflicting files webapp_dist/* need to be resolved on merge. other conflicts I could solve.

ArekKubacki and others added 30 commits February 13, 2023 10:42
This reverts commit 5617240ce1fb15a3796d1ed558cc89f9ba72d8d5.
… "Total Power" and "Total Yield" into registers.
prevent sending 0 as "e_energy_exported" to avoid peaks and gaps in solarweb statistic
@AloisKlingler AloisKlingler marked this pull request as ready for review August 4, 2024 08:12
@spcqike
Copy link

spcqike commented Aug 5, 2024

thanks for your effort.

another thing, it would be good, if your changes would be based on helgeerbe:development or :master, too.

right now, your changes are based on a fork of the upstream project, which makes it difficult to compare or include as there may be many more changes than you actually want to add.

On the other hand, it is now only "+278/-3", which is much less than the previous "+3,652/-2,191". So I think the developer can work with that.

@AloisKlingler
Copy link
Author

thanks for your effort.

another thing, it would be good, if your changes would be based on helgeerbe:development or :master, too.

right now, your changes are based on a fork of the upstream project, which makes it difficult to compare or include as there may be many more changes than you actually want to add.

On the other hand, it is now only "+278/-3", which is much less than the previous "+3,652/-2,191". So I think the developer can work with that.

I am sorry for the confusion
I recognized yesterday that the implementation is already a at least SunSpec meter compatible implementation.
It looks like (at least) fronius inverters then only have additional checks for e.g. vendor to allow them beeing configured.

In a yet (in my repository) not commited change I created configuration for the necessary sunspec fields so it may be compatible with other inverters which do the same.

I will update this PR as soon as I have tested all the changes well enough.

@AloisKlingler AloisKlingler marked this pull request as draft August 6, 2024 06:20
Alois Klingler added 2 commits August 6, 2024 15:18
add configuration for elements to equip with custom vendor strings.
@AloisKlingler AloisKlingler changed the title add fronius smartmeter simulation to opendtu-onbattery add Modbus Sunspec compatibility to opendtu-onbattery Aug 7, 2024
@AloisKlingler AloisKlingler marked this pull request as ready for review August 7, 2024 08:45
@AndreasBoehm
Copy link
Member

AndreasBoehm commented Aug 21, 2024

There are still a lot of unrelated changes, please make sure that you base your branch off of the OpenDTU-OnBattery development branch.

to the PR: the tree conflicting files webapp_dist/* need to be resolved on merge. other conflicts I could solve.

Please do not commit any file within webapp_dist/. This is done by the upstream project OpenDTU but within the OnBattery repo we don't do that, not sure why but i can imagine that its because of the conflicts that would arise constantly.

@@ -76,6 +76,16 @@ struct CONFIG_T {
bool Enabled;
} Mdns;

struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add bool verboseLogging to your struct and use that to enable/disable logging within your Modbus module instead of commenting the logging lines.

@@ -45,6 +45,7 @@ lib_deps =
nrf24/RF24 @ 1.4.9
olikraus/U8g2 @ 2.35.19
buelowp/sunset @ 1.1.7
https://github.com/emelianov/modbus-esp8266#master
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we point to a specific commit or release-tag instead of a branch?
This might break builds at any point in the future without us knowing whats going on.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently not, as there is a change which is most probably needed in master only:
emelianov/modbus-esp8266#292

as soon as there is a 4.1.2 (or whatever) released I think this one could be used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you specific the commit hash with #a5872af7250e03e9a5cd578366b0c2cdc097fcc9 instead of #master you can make sure that the dependency won't get updated randomly with the next push to master

Comment on lines +212 to +223
// mb.Hreg(0x9cbb, 0);
// mb.Hreg(0x9cbc, 0);
// mb.Hreg(0x9cbd, 0);
// mb.Hreg(0x9cbe, 0);
// mb.Hreg(0x9cbf, 0);
// mb.Hreg(0x9cc0, 0);
// value = (inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_YT)*1000); //done above already!
// if (value > _lasttotal) {
// _lasttotal = value;
// mb.Hreg(0x9cc1, hexbytes[1]); //done above already!
// mb.Hreg(0x9cc2, hexbytes[0]); //done above already!
// }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove commented lines if they are not needed


ModbusDtuClass ModbusDtu;

ModbusDtuClass::ModbusDtuClass()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make more sense if we call it ModbusSunspec or SunspecModbus to explain what this is actually doing?

Do you have any documentation about the protocol that youa re implementing here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this implementation is (maybe only partially) modbus-sunspec compatibility to simulate a sunspec energy-meter.

as far as I could google, this should match to "sunspec meter" registers in float mode.
I could not check if it is the complete protocol or only partial.
at least, if I check against fronius documentation, it is complete.

Copy link

github-actions bot commented Feb 1, 2025

This pull-request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Feb 1, 2025
@AloisKlingler
Copy link
Author

@AndreasBoehm @schlimmchen @stefan123t
if I would change the above things, will the PR be merged?
what I can tell, the last released version from https://github.com/AloisKlingler/OpenDTU-FroniusSM-MB/releases/tag/v24.8.5-0.3.1 (the one with this PR) is running absolutely stable for me with one inverter. also about 10-20 users from photovoltaikforum.com use it and do not report issues.

I am not sure when I find time to do the changes requested above. my issue is, that adapting / merging to current OpenDTU versions (or also OpenDTU-OnBattery) is very time consuming caused by my knowledge.

it looks like there are some enhancement requests regarding ModbusTCP, I am happy if I can help, but I maybe need your help too if it is really wanted to be merged.

Thanks.

Best regards
Alois

mb.Hreg(0x9cc2, hexbytes[0]);
}

if (Hoymiles.getNumInverters() == 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if a user has configured multiple inverters?
Now that the DPL supports multiple inverters we shall not limit this feature a single inverter only.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with multiple inverters the modbus data for total power (40097 and 40098) and yieldtotal (40129 and 40130) is filled.
those two values are the important one which are accumulateable easily (like already done in the "Total Yield Total" and "Total Power" in webgui)

other data (like frequency, voltage, etc.) is not filled, as we do not know from which source to take, and accumulating / calculating averages makes no sense at all.
this data is not mandatory (at least not for fronius inverters) to accept the ModbusTCP as smartmeter.

@AndreasBoehm
Copy link
Member

Let's talk about more about what this PR or your feature actually does, at least how i understood it. Please correct me if any of my assumptions are wrong.

  • Its a ModbusTCP server that will be polled by other hardware to get data
  • For this ModbusTCP server you implemented registers according to the 'SunSpec'-protocol

Changes that i would suggest

  • it should have its own settings page as i don't see that its related to 'Network'
  • classes, structs, fields need clear names, keeping ModbusTCPServer in mind
  • cleanup the code, add more comments to make it easier to read and undrstand
  • link a sunspec protocol documentation

I am wondering if this would be something that should be in the upstream project as its not related to having a battery at all?
https://github.com/tbnobody/OpenDTU

@AloisKlingler
Copy link
Author

Let's talk about more about what this PR or your feature actually does, at least how i understood it. Please correct me if any of my assumptions are wrong.

  • Its a ModbusTCP server that will be polled by other hardware to get data
  • For this ModbusTCP server you implemented registers according to the 'SunSpec'-protocol

exactly.

Changes that i would suggest

  • it should have its own settings page as i don't see that its related to 'Network'
  • classes, structs, fields need clear names, keeping ModbusTCPServer in mind
  • cleanup the code, add more comments to make it easier to read and undrstand
  • link a sunspec protocol documentation

I copied existing elements with great difficulty to have the here available settings. I am sure I cannot manage to create its own page

renaming I can do, only the here mentioned? #1150 (comment)

code cleanup I think I can not do satisfying enough. I tried to make the code already best readable as possible for me.

the sunspec protocol documentation looks to be liable to pay costs: https://sunspec.org/sunspec-modbus-specifications/
I had as reference fronius registers (https://www.fronius.com/de/solarenergie/installateure-partner/technische-daten/alle-produkte/anlagen-monitoring/offene-schnittstellen/modbus-tcp) and also kostal registers (https://optosolar.se/produktfiler/modbusprotkollengelskakostalplenticoreplus.pdf)

I am wondering if this would be something that should be in the upstream project as its not related to having a battery at all? https://github.com/tbnobody/OpenDTU

there a previous modbus implementation was asked to offer a PR here.

@stefan123t
Copy link

@AloisKlingler there are three compatibel standards mentioned on the sunspec page you referred to:

  • IEEE 1547-2018 - IEEE Standard for Interconnection and Interoperability of Distributed Energy Resources with Associated Electric Power Systems Interfaces (aka SunSpec)
  • IEEE 2030.5-2018 - IEEE Standard for Smart Energy Profile Application Protocol
  • IEEE 1815-2012 - IEEE Standard for Electric Power Systems Communications-Distributed Network Protocol (DNP3)

I have been able to download the IEEE_1547-2018_SunSpec.pdf PDF specifications for Distributed Energy Resource (DER) interoperability using the protocols defined in IEEE 2030.5-2018, IEEE 1815-2012 and SunSpec ModBus over TCP/IP transport via Ethernet / RS-485 (only the latter) from the above site. The other two are behind a paywall, access to which might be available to scientific researchers.

I agree with you all that it would be worthwhile to include this in the upstream project as it enables a standard ModBus interface besides MQTT and Web API to share data from the Hoymiles DTUs in the OpenDTU project.
Unfortunately @tbnobody and @schlimmchen have shown no need to include this functionality neither here tbnobody#582 nor there tbnobody#1893 so it was tried to add it to OpenDTU-OnBattery as it may be more applicable to integration with other Distribute Energy Resources.

I hope this may be (re-)considered at a later stage, once the PR has been more refined to both projects coding standards.

@github-actions github-actions bot removed the stale label Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants